<?php

  if (isset($_POST['submit0'])) { // If password entered...
    $word = $_POST['password']; // Variable set as entered password
    setcookie('textadmin', $word, time() + 31536000); // Cookie is set
  } else { // If password form filled in previously...
    if (isset($_COOKIE['textadmin'])) { // Check for cookie
      $word = $_COOKIE['textadmin']; // Variable set as cookie
    }
  }

?>

<?php $thisPage = "delete"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Delete a page</title>
<meta name="robots" content="noindex,nofollow" />
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
</head>
<body>

<div id="wrap">

<?php

// Start password routine
  include_once('password.php');
  if ($word != $le_password) {

?>

<!-- password form //-->
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>
<b>Enter password:</b>
<br />
<input type="password" name="password" size="25" maxlength="25" />
<br />
<input type="submit" name="submit0" value="Submit" />
</p>
</form>
<!-- password form_eof //-->

<?php

    // Routine to display password entry error message.
    if (isset($_POST['submit0'])) {
      if ($_POST['password'] != $le_password) {
        echo '<p">Incorrect password!</p>';
      }
    }

  } else {
// End password routine

?>

<?php include_once('navigation.php'); ?>

<?php

  if (isset($_POST['submit'])) { // Handle the form

    // Specify the .php file
    $phpfile = '../' . $_POST['delete'] . '.php';
    // Specify the .txt file
    $txtfile = '../textfiles/' . $_POST['delete'] . '.txt';

    // Check for existence of files
    // php file
    if (file_exists($phpfile)) {
      unlink($phpfile);
      $response1 = 'Success. <b>' . $_POST['delete'] . '.php</b> was deleted.<br />';
    } else {
      $response1 = 'Sorry, <b>' . $_POST['delete'] . '.php</b> does not exist. Try another.<br />';
    }

    // txt file
    if (file_exists($txtfile)) {
      unlink($txtfile);
      $response2 = 'Success. <b>' . $_POST['delete'] . '.txt</b> was deleted.<br />';
    } else {
      $response2 = 'Sorry, <b>' . $_POST['delete'] . '.txt</b> does not exist. Try another.<br />';
    }

  }

?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Name of page to be deleted (eg mypage)<br />
<input type="text" name="delete" id="delete" size="40" value="<?php if (isset($_POST['submit'])) echo $_POST['delete']; ?>" maxlength="60" />
<br />
<input type="submit" name="submit" value="Delete page" />
</form>

<?php echo $response1 . $response2; ?>

<?php include_once('list-all.php'); ?>

<?php

  } // Required for password routine

?>

<div style="clear: both;"></div>
</div>

</body>
</html>